package algorithm;

import java.util.ArrayList;
import java.util.List;

public class leetcode_0078 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> list=new ArrayList<>();
        List<Integer> path=new ArrayList<>();
        list.add(new ArrayList<>(path));
        if(nums.length==0) return list;
        for(int i=0;i<nums.length;++i){
            dfs(list,path,nums,i,false);
        }
        return list;
    }
    public void dfs(List<List<Integer>> list,List<Integer> path,int[] nums,int start,boolean flag){
        if(start==nums.length) {
            list.add(new ArrayList<>(path));
            return;
        }
        if(!flag){
            path.add(nums[start]);
            dfs(list,path,nums,start+1,true);
            path.remove(path.size()-1);
        }
        else{
            path.add(nums[start]);
            dfs(list,path,nums,start+1,true);
            path.remove(path.size()-1);
            dfs(list,path,nums,start+1,true);
        }

    }
}
